<!DOCTYPE html>
<html lang="en">
	<head>
		<title>定时任务列表</title>
		<#include "../inc/header.ftl"/>
	</head>

	<body class="no-skin">

		<div class="main-container ace-save-state" id="main-container">

			<div class="main-content">
				<div class="main-content-inner">

					<div class="page-content">
						<div class="row">
							<div class="col-xs-12">
								<table id="MainGrid"></table>
								<div id="toolbar">
                                    <div style="padding:8px">
                                        区划：<input id="cantonidtop" name="cantonidtop">
                                        <a href="#" onclick="javascript:searchInfo()" class="easyui-linkbutton" iconCls="icon-search">查 询</a>
                                    </div>
                                    <div style="padding:8px 8px 4px">
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="javascript:addInfo()">新增</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="javascript:editInfo()">修改</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="javascript:delInfo()">删除</a>
                                    </div>
								</div>
							</div>
						</div><!-- /.row -->
					</div><!-- /.page-content -->
                    <div id="box-add" class="ui-dialog-content hide">
                        <form class="form-horizontal" id="form-add" method="post">
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-4 no-padding-right">任务名称</label>
                                <div class="col-xs-12 col-sm-6">
									<span class="block input-icon input-icon-right">
										<input type="text" name="jobName" id="jobName" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%" />
                                    </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-4 no-padding-right">组名称</label>
                                <div class="col-xs-12 col-sm-6">
                                    <div class="clearfix">
                                        <input type="text" name="groupName" id="groupName" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%" />
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-4 no-padding-right">任务执行类</label>
                                <div class="col-xs-12 col-sm-6">
                                    <div class="clearfix">
                                        <input type="text" name="jobClass" id="jobClass" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%" />
                                        <span>示例：com.jishuo.quartz.job.AutoCheckJob</span>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-4 no-padding-right">cron表达式</label>
                                <div class="col-xs-12 col-sm-6">
                                    <div class="clearfix">
                                        <input type="text" name="cronExpression" id="cronExpression" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%" />
                                    </div>
                                </div>
                            </div>

                        </form>
                    </div><!-- #dialog-confirm -->
                    <div id="box-edit" class="ui-dialog-content hide">
                        <form class="form-horizontal" id="form-edit" method="post">
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-4 no-padding-right">任务名称</label>
                                <div class="col-xs-12 col-sm-6">
									<span class="block input-icon input-icon-right">
										<input type="text" name="jobName" id="jobName" class="col-xs-12 easyui-textbox" data-options="required:true" readonly="readonly" style="width:100%" />
                                    </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-4 no-padding-right">组名称</label>
                                <div class="col-xs-12 col-sm-6">
                                    <div class="clearfix">
                                        <input type="text" name="groupName" id="groupName" class="col-xs-12 easyui-textbox" data-options="required:true" readonly="readonly" style="width:100%" />
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-4 no-padding-right">cron表达式</label>
                                <div class="col-xs-12 col-sm-6">
                                    <div class="clearfix">
                                        <input type="text" name="cronExpression" id="cronExpression" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%" />
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div><!-- #dialog-confirm -->
                </div>
			</div><!-- /.main-content -->
		</div><!-- /.main-container -->

		<!-- basic scripts -->
		<#include "../inc/basicjs.ftl"/>

		<!-- inline scripts related to this page -->
		<script type="text/javascript">
            //列表-------------------------------------------------
			jQuery(function($) {
				// 右侧表格
				$('#MainGrid').datagrid({
					url: prefix + '/quartz/getTaskList',
                    checkbox: true,
                    pagination: true,
                    fitColumns:true,
                    striped: true,
                    singleSelect: true,
					loadMsg: "正在加载数据，请稍后...",
					queryParams: {},
					columns:[[
                        { title: '任务名称',	field: 'jobName',width:100},
                        { title: '组名称',	field: 'groupName',width:210},
                        { title: '任务表达式',	field: 'cronExpression',width:100}
					]],
					toolbar: '#toolbar'
				});

				$(window).resize(function() {
					$('#MainGrid').datagrid('resize');
				});
			});

            function searchInfo() {
                $('#MainGrid').datagrid('load',{});
            }

            function addInfo() {
                $('#form-add').form('clear');
                $( "#box-add" ).removeClass('hide').dialog({
                    title: '&nbsp;新增',
                    iconCls:'icon-add',
                    width: 600,
                    height: 400,
                    modal: true,
                    buttons:[{
                        text:'新增' ,
                        iconCls:'icon-ok',
                        width:80,
                        plain:false,
                        handler:function(){
                            saveInfo();
                        }
                    },{
                        text:'取消',
                        iconCls:'icon-cancel',
                        width:80,
                        plain:false,
                        handler:function(){$('#box-add').dialog('close')}
                    }]
                });
            }
            function editInfo() {
                var row = $('#MainGrid').datagrid('getSelected');
                if (row == null) {
                    $.messager.alert('提示', '请选择要编辑的数据', 'info');
                    return;
                }
                $('#form-edit').form('load',row);

                $( "#box-edit" ).removeClass('hide').dialog({
                    title: '&nbsp;修改',
                    iconCls:'icon-edit',
                    width: 600,
                    height: 400,
                    modal: true,
                    buttons:[{
                        text:'修改' ,
                        iconCls:'icon-ok',
                        width:80,
                        plain:false,
                        handler:function(){
                            update();
                        }
                    },{
                        text:'取消',
                        iconCls:'icon-cancel',
                        width:80,
                        plain:false,
                        handler:function(){$('#box-edit').dialog('close')}
                    }]
                });
            }

            function delInfo() {
                var row = $('#MainGrid').datagrid('getSelected');
                if (row == null) {
                    $.messager.alert('提示', '请选择要删除的数据', 'info');
                    return;
                }
                $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
                    if (r){
                        $.ajax({
                            url: prefix +'/quartz/deleteJob',
                            type: 'POST',
                            data: {
                                jobName:row.jobName,
                                groupName:row.groupName
                            },
                            dataType: 'json',
                            success:function(data){
                                searchInfo();
                                $.messager.alert('提示', data.msg, 'info');
                            }
                        });
                    } else{//没选中
                        return false;
                    }
                })
            }

            function saveInfo() {
                $('#form-add').form({
                    url: prefix +'/quartz/addJob',
                    onSubmit:function(){
                        var isValid = $(this).form('validate');
                        if (isValid){
                            $.messager.progress({
                                title: '提示',
                                msg: '数据处理中，请稍候……',
                                text: ''
                            });
                        }
                        return isValid;
                    },
                    success:function(data) {
                        $.messager.progress('close');
                        var data = eval('(' + data + ')');
                        if(data.success) {
                            $('#box-add').dialog('close');
                            searchInfo();
                        }
                        $.messager.alert('提示', data.msg, 'info');
                    }
                });
                $('#form-add').submit();
            }
            function update() {
                $('#form-edit').form({
                    url: prefix +'/quartz/updateJob',
                    onSubmit:function(){
                        var isValid = $(this).form('validate');
                        if (isValid){
                            $.messager.progress({
                                title: '提示',
                                msg: '数据处理中，请稍候……',
                                text: ''
                            });
                        }
                        return isValid;
                    },
                    success:function(data) {
                        $.messager.progress('close');
                        var data = eval('(' + data + ')');
                        if(data.success) {
                            $('#box-edit').dialog('close');
                            searchInfo();
                        }
                        $.messager.alert('提示', data.msg, 'info');
                    }
                });
                $('#form-edit').submit();
            }

        </script>
	</body>
</html>
